package com.shop.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.shop.service.AdminService;
import com.shop.service.impl.AdminServiceImpl;

@WebServlet("/login.do")
public class LoginAdminServlet extends HttpServlet {
	
	AdminService adminService = new AdminServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String account = request.getParameter("account");
		String password = request.getParameter("password");
		Map<String,Object> result = adminService.selectAdmin(account, password);
		if(result.get("adminLogin") != null) {//登录验证后跳转商品页面
			HttpSession session = request.getSession();
			session.setAttribute("adminLogin", result.get("adminLogin"));
			response.sendRedirect("selectGoods.do");
					
		}else {
			request.setAttribute("msg",result.get("msg"));
			request.getRequestDispatcher("index.jsp").forward(request, response);
		}
	}



}
